package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.CrmCustomerInfoAddDTO;
import org.jsola.hr.dto.CrmCustomerInfoUpdateDTO;
import org.jsola.hr.entity.CrmCustomerInfoDO;
import org.jsola.hr.query.CrmCustomerInfoQuery;
import org.jsola.hr.service.ICrmCustomerInfoService;
import org.jsola.hr.vo.CrmCustomerInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 客户详情表
 *
 * @author zhr
 */
@Component
public class CrmCustomerInfoTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICrmCustomerInfoService crmCustomerInfoService;

    /**
     * 生成add测试数据
     * @return CrmCustomerInfoAddDTO
     */
    public CrmCustomerInfoAddDTO getCrmCustomerInfoAddDTO(){
        CrmCustomerInfoAddDTO crmCustomerInfoAddDTO = new CrmCustomerInfoAddDTO();
        crmCustomerInfoAddDTO.setDistributeName(getRandomValue("varchar",50));
        crmCustomerInfoAddDTO.setIsPublic(SafeKit.getBoolean(getRandomValue("tinyint",50)));
        crmCustomerInfoAddDTO.setSourceUserId(getRandomValue("varchar",50));
        crmCustomerInfoAddDTO.setEntryName(getRandomValue("varchar",50));
        crmCustomerInfoAddDTO.setProductName(getRandomValue("varchar",50));
        crmCustomerInfoAddDTO.setName(getRandomValue("varchar",32));
        crmCustomerInfoAddDTO.setPhone(getRandomValue("varchar",32));
        crmCustomerInfoAddDTO.setGender(SafeKit.getInteger(getRandomValue("int",1)));
        crmCustomerInfoAddDTO.setType(SafeKit.getInteger(getRandomValue("int",1)));
        crmCustomerInfoAddDTO.setEmail(getRandomValue("varchar",32));
        crmCustomerInfoAddDTO.setWechat(getRandomValue("varchar",32));
        crmCustomerInfoAddDTO.setFax(getRandomValue("varchar",32));
        crmCustomerInfoAddDTO.setPostName(getRandomValue("varchar",32));
        crmCustomerInfoAddDTO.setCustomerSituation(getRandomValue("varchar",100));
        crmCustomerInfoAddDTO.setCustomerDemand(getRandomValue("varchar",100));
        crmCustomerInfoAddDTO.setCustomerIntroduce(getRandomValue("varchar",100));
        crmCustomerInfoAddDTO.setMark(getRandomValue("varchar",100));
        crmCustomerInfoAddDTO.setUserId(getRandomValue("varchar",100));
        crmCustomerInfoAddDTO.setMemberId(getRandomValue("varchar",100));
        crmCustomerInfoAddDTO.setMemberName(getRandomValue("varchar",100));
        crmCustomerInfoAddDTO.setSourceType(SafeKit.getInteger(getRandomValue("int",1)));
        crmCustomerInfoAddDTO.setSourceName(getRandomValue("varchar",100));
        crmCustomerInfoAddDTO.setDistributeOrGetTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        crmCustomerInfoAddDTO.setLastVisitTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        crmCustomerInfoAddDTO.setRemoveReason(getRandomValue("varchar",100));
        crmCustomerInfoAddDTO.setLegalPersonName(getRandomValue("varchar",32));
        crmCustomerInfoAddDTO.setLegalPersonPhone(getRandomValue("varchar",32));
        crmCustomerInfoAddDTO.setLegalPersonGender(SafeKit.getInteger(getRandomValue("int",1)));
        crmCustomerInfoAddDTO.setLegalPersonEmail(getRandomValue("varchar",32));
        crmCustomerInfoAddDTO.setLegalPersonWechat(getRandomValue("varchar",32));
        crmCustomerInfoAddDTO.setLegalPersonPostName(getRandomValue("varchar",32));
        crmCustomerInfoAddDTO.setCompanyName(getRandomValue("varchar",100));
        crmCustomerInfoAddDTO.setCompanyAddress(getRandomValue("varchar",100));
        crmCustomerInfoAddDTO.setCompanyType(SafeKit.getInteger(getRandomValue("int",1)));
        crmCustomerInfoAddDTO.setCompanyPersonSize(SafeKit.getInteger(getRandomValue("int",1)));
        crmCustomerInfoAddDTO.setCompanyIndustry(getRandomValue("varchar",100));
        crmCustomerInfoAddDTO.setEstimatedSigningTime((Date)ClassKit.getObjectValue(getRandomValue("date",0),"java.util.Date"));
        crmCustomerInfoAddDTO.setSigningTime((Date)ClassKit.getObjectValue(getRandomValue("date",0),"java.util.Date"));
        crmCustomerInfoAddDTO.setEstimatedDistributeTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        crmCustomerInfoAddDTO.setDistributeTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        crmCustomerInfoAddDTO.setContract(getRandomValue("varchar",500));
        crmCustomerInfoAddDTO.setContractName(getRandomValue("varchar",100));
        crmCustomerInfoAddDTO.setBusinessLicense(getRandomValue("varchar",500));
        crmCustomerInfoAddDTO.setContractStartTime((Date)ClassKit.getObjectValue(getRandomValue("date",0),"java.util.Date"));
        crmCustomerInfoAddDTO.setContractEndTime((Date)ClassKit.getObjectValue(getRandomValue("date",0),"java.util.Date"));
        crmCustomerInfoAddDTO.setCooperativeProducts(getRandomValue("varchar",100));
        crmCustomerInfoAddDTO.setIsSign(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        return crmCustomerInfoAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CrmCustomerInfoUpdateDTO
     */
    public CrmCustomerInfoUpdateDTO getCrmCustomerInfoUpdateDTO(CrmCustomerInfoVO crmCustomerInfoVO){
        return crmCustomerInfoService.selectDOById(crmCustomerInfoVO.getId(), SITE_ID).to(CrmCustomerInfoUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CrmCustomerInfoQuery
     */
    public CrmCustomerInfoQuery getCrmCustomerInfoQuery() {
        CrmCustomerInfoQuery crmCustomerInfoQuery = new CrmCustomerInfoQuery();
        List<CrmCustomerInfoDO> crmCustomerInfoDOList = crmCustomerInfoService.list(new CrmCustomerInfoDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(crmCustomerInfoDOList)) {
            CrmCustomerInfoDO crmCustomerInfoDO = crmCustomerInfoDOList.get(0);
            crmCustomerInfoQuery = crmCustomerInfoDO.to(CrmCustomerInfoQuery.class);
        }
        return crmCustomerInfoQuery;
    }

    /**
     * 保存示例
     * @return CrmCustomerInfoVO
     */
    public CrmCustomerInfoVO saveCrmCustomerInfoExample(){
        CrmCustomerInfoAddDTO addDTO = this.getCrmCustomerInfoAddDTO();
        CrmCustomerInfoVO crmCustomerInfoVO = crmCustomerInfoService.save(addDTO,buildTokenUser());
        return crmCustomerInfoVO;
    }


}

